// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using NUnit.Framework;
using ValidationAspects.Exceptions;

namespace TestValidationAspects.Exceptions
{
	[TestFixture]
	public class TestValidateLengthInRangeException
	{
		[SetUp]
		public void SetUp()
		{
			ValidateLengthInRangeException.ResetMessageFormat();
		}

		[Test]
		public void Test_Constructor()
		{
			ValidateLengthInRangeException exception = new ValidateLengthInRangeException(1, 2, 3);
			Assert.AreEqual(1, exception.Minimum);
			Assert.AreEqual(2, exception.Maximum);
			Assert.AreEqual(3, exception.Value);
		}

		[Test]
		public void Test_default_MessageFormat()
		{
			ValidateLengthInRangeException exception = new ValidateLengthInRangeException(1, 2, 3);
			Assert.AreEqual(string.Format("{0} length must be within range {1} to {2}.", exception.GetValidationTargetName(), 1, 2), ValidateLengthInRangeException.MessageFormat(exception));
		}

		[Test]
		public void Test_get_Message_executes_MessageFormat()
		{
			const string message = "custom message";
			ValidateLengthInRangeException.MessageFormat = e => message;
			Assert.AreEqual(message, new ValidateLengthInRangeException(1, 2, 3).Message);
		}

		[Test]
		public void Test_ResetMessageFormat()
		{
			const string message = "custom message";
			ValidateLengthInRangeException.MessageFormat = e => message;

			ValidateLengthInRangeException exception = new ValidateLengthInRangeException(1, 2, 3);
			Assert.AreEqual(message, exception.Message);

			ValidateLengthInRangeException.ResetMessageFormat();
			Assert.AreEqual(string.Format("{0} length must be within range {1} to {2}.", exception.GetValidationTargetName(), 1, 2), ValidateLengthInRangeException.MessageFormat(exception));
		}
	}
}